package com.malty.mall.domain.dto.req.pms;

import com.malty.mall.domain.entity.pms.PmsProductAttributeCategory;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author malty
 */
@Data
@NoArgsConstructor
@ApiModel("商品属性分类")
public class PmsAttributeCategoryParam {
    @ApiModelProperty("id")
    private Long id;
    @ApiModelProperty("分类名称")
    @NotEmpty(message = "属性名称不能为空")
    private String name;
    @ApiModelProperty("该分类属性数量")
    @NotNull(message = "属性数量不能为空")
    private Long attributeCount;
    @ApiModelProperty("该分类参数数量")
    @NotNull(message = "参数数量不能为空")
    private Long paramCount;

    public PmsAttributeCategoryParam(PmsProductAttributeCategory category) {
        if (category != null) {
            BeanUtils.copyProperties(category, this);
        }
    }

    public static List<PmsAttributeCategoryParam> attributeCateParams(List<PmsProductAttributeCategory> records) {
        List<PmsAttributeCategoryParam> categoryParams = new ArrayList<>();
        for (PmsProductAttributeCategory category : records) {
            categoryParams.add(new PmsAttributeCategoryParam(category));
        }
        return categoryParams;
    }
}
